package com.distance;

import com.claim.ViewClaimClient;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.kmlparser.RouteHistoryParser;
import com.overlays.EndMarker;
import com.overlays.RouteLine;
import com.overlays.StartMarker;
import com.overlays.ViewClaimRouteLine;
import com.route.DetailedLocation;
import com.route.Route;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class ViewClaim extends MapActivity {
    private TextView textView;
    private MapView viewClaimMapView;
    private Drawable startPointer;
    private Drawable endPointer;
    private ViewClaimRouteLine routeLineOverlay;
    private ViewClaimClient viewClaimClient;
    private Menu mMenu;
    private MenuItem mItem1;
    private MenuItem mItem2;

    @Override
    protected void onCreate(Bundle icicle) {
	super.onCreate(icicle);
	setContentView(R.layout.viewclaim);
	viewClaimMapView = (MapView) findViewById(R.id.ViewClaimMap);
	textView = (TextView) findViewById(R.id.ViewClaimTV01);
	textView.bringToFront();
	routeLineOverlay = new ViewClaimRouteLine(getApplicationContext());
	startPointer = getResources().getDrawable(R.drawable.start);
	startPointer.setBounds(0, 0, startPointer.getIntrinsicWidth(),
		startPointer.getIntrinsicHeight());

	endPointer = getResources().getDrawable(R.drawable.end);
	endPointer.setBounds(0, 0, endPointer.getIntrinsicWidth(), endPointer
		.getIntrinsicHeight());
	viewClaimClient = new ViewClaimClient();
	RouteHistoryParser.claimDetailReader(viewClaimClient.viewClaim());
	viewClaimMapView.getOverlays().add(routeLineOverlay);
	viewClaimMapView.getOverlays().add(new StartMarker(startPointer, com.claim.Claim.start.getGeoPoint(), getApplicationContext()));
	viewClaimMapView.getOverlays().add(new EndMarker(endPointer, com.claim.Claim.end.getGeoPoint(), getApplicationContext()));
	viewClaimMapView.getController().setCenter(com.claim.Claim.start.getGeoPoint());
	textView.setText("Start Location: " + com.claim.Claim.start.getLocationName() + " (" + com.claim.Claim.start.getGeoPoint().toString() + ")\nStart Location: " + com.claim.Claim.end.getLocationName() + " (" + com.claim.Claim.end.getGeoPoint().toString()+ ")\nDistance " + com.claim.Claim.routeLength.toString() + " meters");
	textView.setTextColor(Color.WHITE);
	textView.setBackgroundColor(Color.argb(255, 0, 0, 0));
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
	mMenu = menu;
	
	mItem1 = mMenu.add("Use Route");
	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
	if (item.equals(mItem1)) {
	    com.route.Route.start = com.claim.Claim.start;
	    com.route.Route.end = com.claim.Claim.end;
	    com.route.Route.markers = com.claim.Claim.markers;
	    com.route.Route.routeLength = com.claim.Claim.routeLength;
	    com.route.Route.fromClaim = true;
	    Intent intent = new Intent();
	    intent.setClassName("com.distance", "com.distance.Distance");
	    startActivity(intent);
	    return true;
	}
	return false;
	
    }

    @Override
    protected boolean isRouteDisplayed() {
	return true;
    }

}
